package peace.util
{
import flash.net.registerClassAlias;
import flash.utils.ByteArray;
import flash.utils.getQualifiedClassName;
	
/**
 * 
 * @author peace
 * 
 */
public class Objects
{
	/**
	 * 
	 * @param source
	 * @param needRegisterClassAlias
	 * @return 
	 * 
	 */
	public static function clone(source:Object, needRegisterClassAlias:Boolean = false):* 
	{
	    if (needRegisterClassAlias)
	    {
	    	registerClassAlias(getQualifiedClassName(source), source.constructor);
	    }
	    
	    var copier:ByteArray = new ByteArray();
	    copier.writeObject(source);
	    copier.position = 0;
	    return(copier.readObject());
	}	
	
	
}
}